﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using SpotTheMisspell.Views;

namespace SpotTheMisspell
{
    public partial class MainPage : PhoneApplicationPage
    {
        private EventHandler<SimpleMvvmToolkit.NotificationEventArgs<Exception>> evHandler;
        private MainPageViewModel model;
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            model = (MainPageViewModel) LayoutRoot.DataContext;
            evHandler = new EventHandler<SimpleMvvmToolkit.NotificationEventArgs<Exception>>(model_ErrorNotice);
            model.ErrorNotice += evHandler;
        }

        void model_ErrorNotice(object sender, SimpleMvvmToolkit.NotificationEventArgs<Exception> e)
        {
            
            MessageBox.Show(e.Message);
            model.ErrorNotice -= evHandler;
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            ((MainPageViewModel)LayoutRoot.DataContext).startGame();
        }

      
    }
}